package com.ai.emall.api.productmanage.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.ai.emall.business.interfaces.IProductManageDealSV;
import com.ai.emall.business.interfaces.IProductManageQuerySV;
import com.ai.emall.utils.constants.SysExceptCodeConstants;
import com.ai.emall.utils.exception.BusinessException;
import com.ai.emall.utils.util.CollectionUtil;
import com.ai.gcf.api.base.vo.ResponseHeader;
import com.ai.gcf.api.emall.productmanage.interfaces.IProductManageDealDubboSV;
import com.ai.gcf.api.emall.productmanage.param.ModifyProductInfoRequest;
import com.ai.gcf.api.emall.productmanage.param.ModifyProductInfoResponse;
import com.ai.gcf.api.emall.productmanage.param.ModifyProductSortRequest;
import com.ai.gcf.api.emall.productmanage.param.ModifyProductSortResponse;
import com.ai.gcf.api.emall.productmanage.param.ModifyProductStatusRequest;
import com.ai.gcf.api.emall.productmanage.param.ModifyProductStatusResponse;
import com.ai.gcf.api.emall.productmanage.param.SaveProductInfoRequest;
import com.ai.gcf.api.emall.productmanage.param.SaveProductInfoResponse;

/** 
 * 产品增加，编辑，删除等操作
 * @author zhaowg3
 * @Date 2016年12月29日
 */
public class ProductManageDealDubboSVImpl implements IProductManageDealDubboSV {
	@Autowired
	private IProductManageDealSV iProductManageDealSV;

	@Override
	public SaveProductInfoResponse saveProductInfo(SaveProductInfoRequest request) throws Exception {
		if(request == null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数为空");
		if(StringUtils.isBlank(request.getModuleId()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "模块ID为空");
		Long productId = iProductManageDealSV.saveProductInfo(request);
		SaveProductInfoResponse response = new SaveProductInfoResponse();
		response.setProductId(productId);
		response.setResponseHeader(new ResponseHeader(SysExceptCodeConstants.Special.SUCCESS, "成功"));
		return response;
	}

	@Override
	public ModifyProductInfoResponse modifyProductInfo(ModifyProductInfoRequest request) throws Exception {
		if(request == null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数为空");
		if(request.getProductId()==null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "产品ID为空");
		iProductManageDealSV.modifyProductInfo(request);
		ModifyProductInfoResponse response = new ModifyProductInfoResponse();
		response.setResponseHeader(new ResponseHeader(SysExceptCodeConstants.Special.SUCCESS, "成功"));
		return response;
	}

	@Override
	public ModifyProductStatusResponse ModifyProductStatus(ModifyProductStatusRequest request) throws Exception {
		if(request == null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数为空");
		if(CollectionUtil.isEmpty(request.getProductIds()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "产品IDs为空");
		if(StringUtils.isBlank(request.getStatus()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "状态为空");
		iProductManageDealSV.modifyProductStatus(request.getProductIds(),request.getStatus(),request.getOperId());
		ModifyProductStatusResponse  response = new ModifyProductStatusResponse();
		response.setResponseHeader(new ResponseHeader(SysExceptCodeConstants.Special.SUCCESS, "成功"));
		return response;
	}

	@Override
	public ModifyProductSortResponse ModifyProductSort(ModifyProductSortRequest request) throws Exception {
		if(request == null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数为空");
		if(request.getProductId() == null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "产品IDs为空");
		if(request.getSortType()==null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "排序类型为空");
		if(StringUtils.isBlank(request.getModuleId()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "模块ID为空");
		iProductManageDealSV.modifyProductSort(request.getProductId(), request.getSortType(), request.getModuleId(), request.getOperId());
		ModifyProductSortResponse response = new ModifyProductSortResponse();
		response.setResponseHeader(new ResponseHeader(SysExceptCodeConstants.Special.SUCCESS, "成功"));
		return response;
	}

}
